import QtQuick 2.0
import QtQuick.Window 2.1

Window {
    id: list_widget_father
    flags: Qt.FramelessWindowHint | Qt.Popup

    width: 400
    height: 500

    property int title_count: 2
    property int title_height: 30
    property int window_flags: 0

    function disvisible_widgets(except_index) {
        if (except_index != 1)
            playing_list.visible = false
        else if (except_index != 2)
            online_list.visible = false
    }

    function insert_element(list_index, classific_index, index, object) {
        if (list_index == 1) {
            playing_list.insert_element(index, object)
        } else if (list_index == 2) {
            if (index == -1) {
                online_list.insert_classific_elemnt(classific_index, object)
            } else {
                online_list.insert_element(classific_index, index, object)
            }
        }
    }

    Rectangle {
        id: list_widget
        anchors.fill: parent

        Rectangle {
            id: playing_list_title
            Text {
                x: 10
                y: playing_list_title.height - title_height + 15 - 5
                text: "Play List"
                font.pixelSize: title_height - 15
            }

            gradient: Gradient {
                GradientStop { position: 0.0; color: "#9db7d5" }
                GradientStop { position: 0.33; color: "#3b5283" }
                GradientStop { position: 1.0; color: "#3b5283" }
            }
//            color: "#9db7d5"
            height: title_height
            width: list_widget.width
            MouseArea {
                id: play_mouse_area
                anchors.fill: parent
                onClicked: {
                    disvisible_widgets(1)
                    playing_list.visible = true
                }
            }
        }

        ScrollWidget {
            id: playing_list
            y: playing_list_title.y + playing_list_title.height + 5
            width: list_widget.width
            height: list_widget.height - title_count * title_height
            visible: false
        }

        Rectangle {
            id: online_list_title
            Text {
                x: 10
                y: playing_list_title.height - title_height + 15 - 5
                text: "Online List"
                font.pixelSize: title_height - 15
            }
            gradient: Gradient {
                GradientStop { position: 0.0; color: "#9db7d5" }
                GradientStop { position: 0.33; color: "#3b5283" }
                GradientStop { position: 1.0; color: "#3b5283" }
            }
            height: title_height
            width: list_widget.width
            y: {
                if (playing_list.visible)
                    playing_list.y + playing_list.height
                else
                    playing_list_title.y + playing_list_title.height
            }
            MouseArea {
                id: online_mouse_area
                anchors.fill: parent
                onClicked: {
                    disvisible_widgets(2)
                    online_list.visible = true
                }
            }
        }

        ScrollWidget {
            id: online_list
            y: online_list_title.y + online_list_title.height + 5
            width: list_widget.width
            height: list_widget.height - title_count * title_height
            visible: false
        }
    }

//    Component.onCompleted: {
//        insert_element(1, -1, 0, {name: "hello world"})
//    }
}
